import java.util.*;

public class test {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // 初始化位示图，64块存储器
        boolean[] bitMap = new boolean[64];
        Arrays.fill(bitMap, false);

        // 已占用的内存块
        int[] occupiedBlocks = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19};
        for (int block : occupiedBlocks) {
            bitMap[block] = true;
        }

        // 输入每个进程申请的内存块数
        int[] requests = new int[4];
        for (int i = 0; i < 4; i++) {
            requests[i] = scanner.nextInt();
        }

        // 输入需要查询的进程号和页号
        int processId = scanner.nextInt();
        int pageId = scanner.nextInt();

        // 检查进程号和页号是否有效
        if (processId < 1 || processId > 4) {
            System.out.println("wait");
            return;
        }
        if (pageId < 0 || pageId >= requests[processId - 1]) {
            System.out.println("error");
            return;
        }

        // 检查是否有足够的内存分配给各个进程
        List<List<Integer>> allocations = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            allocations.add(new ArrayList<>());
        }

        int availableBlocks = 64 - occupiedBlocks.length; // 可用的内存块数
        if (availableBlocks < Arrays.stream(requests).sum()) {
            System.out.println("wait");
            return;
        }

        // 按顺序扫描位示图，为每个进程分配内存
        int currentBlock = 0;
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < requests[i]; j++) {
                // 找到第一个空块
                while (currentBlock < 64 && bitMap[currentBlock]) {
                    currentBlock++;
                }
                if (currentBlock < 64) {
                    allocations.get(i).add(currentBlock);
                    bitMap[currentBlock] = true;
                }
            }
        }

        // 输出结果
        if (allocations.get(processId - 1).size() > pageId) {
            System.out.println(allocations.get(processId - 1).get(pageId));
        } else {
            System.out.println("error");
        }
    }
}
